package com.simple.portal.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.portal.dao.IGroupApplicationRightDAO;
import com.simple.portal.vo.GroupApplicationRightVO;
import com.simple.util.common.Constants;

@Repository("groupApplicationRightDAO")
public class GroupApplicationRightDAOImpl extends BaseDAO implements IGroupApplicationRightDAO{

	@Override
	public GroupApplicationRightVO findById(final String id) {
		
		return (GroupApplicationRightVO)super.get(GroupApplicationRightVO.class, id);
	}

	@Override
	public void save(final GroupApplicationRightVO groupApplicationRightVO,final String operator) {
		
		GroupApplicationRightVO tempGroupApplicationRightVO = super.save(groupApplicationRightVO);
		super.saveLogger(operator, tempGroupApplicationRightVO, tempGroupApplicationRightVO.getGroupId(),Constants.LOGGER_OPERATE_FLAG_ADD);
	}
	
	@Override
	public void update(final GroupApplicationRightVO groupApplicationRightVO,final String type,final String operator) {
		
		super.update(groupApplicationRightVO);
		super.saveLogger(operator, groupApplicationRightVO, groupApplicationRightVO.getGroupId(),type);
	}

	@Override
	public List<GroupApplicationRightVO> findAll() {
		
		return super.query(GroupApplicationRightVO.class);
	}

	@Override
	public void delete(final GroupApplicationRightVO groupApplicationRightVO,final String operator) {
		
		super.delete(groupApplicationRightVO);
		super.saveLogger(operator, groupApplicationRightVO, groupApplicationRightVO.getGroupId(), Constants.LOGGER_OPERATE_FLAG_DELETE);
	}

	@Override
	public void delete(final String id,final String operator) {
		GroupApplicationRightVO groupApplicationRightVO = findById(id);
		super.delete(GroupApplicationRightVO.class, id);
		super.saveLogger(operator, groupApplicationRightVO, groupApplicationRightVO.getGroupId(), Constants.LOGGER_OPERATE_FLAG_DELETE);
	}
	
	@Override
	public List<GroupApplicationRightVO> findGroupApplicationRightByGroup(final String groupId){
		final List<String> params = new ArrayList<String>();
		final String hql = " from GroupApplicationRightVO g where g.GroupId=? ";
		params.add(groupId);
		return super.query(hql, params);
	}

}
